package com.jy.adscm.wechat.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.wechat.bean.QueryWechatRepair;
import com.jy.adscm.wechat.bean.WechatRepair;
import com.jy.adscm.wechat.bean.WechatRole;
import com.jy.adscm.wechat.bean.WechatUser;
import com.jy.adscm.wechat.service.WechatRepairService;
import com.jy.adscm.wechat.service.WechatUserRoleService;
import com.jy.adscm.wechat.utils.RedisOperator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 报修单 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-09-25
 */
@RestController
@RequestMapping("adscm/wechat/wechatRepair")
public class WechatRepairController {
    @Autowired
    private RedisOperator redis;
    @Autowired
    WechatRepairService  WechatRepairService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody WechatRepair wechatRepair, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        Boolean result=  WechatRepairService.insertWechatRepair(wechatRepair,openid);
        return  new SimpleCoreResponse("200","新增成功",result);
    }
    @RequestMapping("select")
    public SimpleCoreResponse select(@RequestBody QueryWechatRepair queryWechatRepair, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        queryWechatRepair.setOpenid(openid);
        Page<WechatRepair> page =new Page<>(queryWechatRepair.getCurrentPage(),queryWechatRepair.getPageSize());
        page=  WechatRepairService.selectWechatRepair(page,queryWechatRepair);
        return  new SimpleCoreResponse("200","查询成功",page);
    }
    @RequestMapping("update")
    public SimpleCoreResponse update(@RequestBody WechatRepair wechatRepair, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        Boolean result=  WechatRepairService.updateWechatRepair(wechatRepair,openid);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
    @RequestMapping("selectById/{id}")
    public SimpleCoreResponse selectById(@PathVariable Long id, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        WechatRepair wechatRepair=  WechatRepairService.selectWechatRepairById(id);
        return  new SimpleCoreResponse("200","修改成功",wechatRepair);
    }
    @RequestMapping("deleteById/{id}")
    public SimpleCoreResponse deleteById(@PathVariable Long id, HttpServletRequest request)throws AdscmSystemException {
        String sessionKey = request.getParameter("sessionKey");
        String openid = redis.get(sessionKey);
        Boolean result  =  WechatRepairService.deleteWechatRepairById(id);
        return  new SimpleCoreResponse("200","修改成功",result);
    }
}

